package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class AddMoviePage extends InternalPage {
        @FindBy(name = "imdbid")
        public WebElement IMBD;
        
        @FindBy(name = "name")
        public WebElement title;

        @FindBy(name = "year")
        public WebElement year;
        
        @FindBy(name = "aka")
        public WebElement knownAs;
        
        @FindBy(name = "duration")
        public WebElement duration;
        
        @FindBy(name = "rating")
        public WebElement rating;

        @FindBy(name = "format")
        public WebElement format;

        @FindBy(id = "own_yes")
        public WebElement own_yes;
        
        @FindBy(id = "own_no")
        public WebElement own_no;

        @FindBy(id = "seen_yes")
        public WebElement seen_yes;

        @FindBy(id = "seen_no")
        public WebElement seen_no;
        
        @FindBy(id = "loaned_yes")
        public WebElement loaned_yes;
        
        @FindBy(id = "loaned_no")
        public WebElement loaned_no;

        @FindBy(name = "loanname")
        public WebElement loanName;

        @FindBy(name = "loandate")
        public WebElement loanDate;

        @FindBy(name = "cover")
        public WebElement coverURL;

        @FindBy(name = "trailer")
        public WebElement url;

        @FindBy(name = "notes")
        public WebElement notes;

        @FindBy(name = "taglines")
        public WebElement tags;

        @FindBy(name = "plotoutline")
        public WebElement plotOutlines;

        @FindBy(name = "plots")
        public WebElement plots;

        @FindBy(id = "text_languages_0")
        public WebElement lang;

        @FindBy(name = "subtitles")
        public WebElement subtitles;

        @FindBy(name = "audio")
        public WebElement audio;

        @FindBy(name = "video")
        public WebElement video;

        @FindBy(name = "country")
        public WebElement country;

        @FindBy(name = "genres")
        public WebElement genre;

        @FindBy(name = "director")
        public WebElement director;

        @FindBy(name = "writer")
        public WebElement writer;

        @FindBy(name = "producer")
        public WebElement producer;

        @FindBy(name = "music")
        public WebElement music;

        @FindBy(name = "cast")
        public WebElement cast;
        
        @FindBy(id = "submit")
        public WebElement submitButton;
        
        public FilmPage submitForm() {
    		submitButton.click();
    		return MyPageFactory.getPage(driver, FilmPage.class);
    	}
        
        public FilmPage fillFormWithDefault() {
    		IMBD.clear();
    		IMBD.sendKeys("1");
    		title.clear();
    		title.sendKeys(filmTestTitle);
    		knownAs.clear();
    		knownAs.sendKeys("Known as");
    		year.clear();
    		year.sendKeys("1985");
    		duration.clear();
    		duration.sendKeys("120");
    		rating.clear();
    		rating.sendKeys("5");
    		format.clear();
    		format.sendKeys("dvd");
    		own_yes.click();
    		seen_yes.click();
    		loaned_yes.click();
    		loanName.clear();
    		loanName.sendKeys("loan name");
    		loanDate.clear();
    		loanDate.sendKeys("2002");
    		url.clear();
    		url.sendKeys("http://test.com");
    		notes.clear();
    		notes.sendKeys("notes");
    		tags.clear();
    		tags.sendKeys("tags");
    		plotOutlines.clear();
    		plotOutlines.sendKeys("plotOutlines");
    		plots.clear();
    		plots.sendKeys("plots");
    		lang.clear();
    		lang.sendKeys("English");
    		subtitles.clear();
    		subtitles.sendKeys("yes");
    		country.clear();
    		country.sendKeys("UK");
    		genre.clear();
    		genre.sendKeys("comedy");
    		submitButton.click();
    		return MyPageFactory.getPage(driver, FilmPage.class);
    	}


    	public boolean verifyIfFilmChangesSaved(String titles, String IMBDs) {
    		if (!IMBD.getAttribute("value").equals(IMBDs) || !title.getAttribute("value").equals(titles)) {
    			errorMes = "Some of the values weren't saved";
    			return false;
    		} else {
    			return true;
    		}
    	}
    	
        public boolean isOnThisPage(){
    		return duration.isDisplayed();
    	}
}
